from web import APP, DB
from web.models import User

@APP.cli.command()
def CreateDB():
    '''创建数据库'''
    DB.create_all()

@APP.cli.command()
def CreateUser():
    '''创建测试用户'''
    sql = User.query.filter(User.username == 'root').first()
    if not sql:
        user1 = User(username='root', password='abc@123', phone='1351111111', email='admin@163.com',
                     remark='engineer')
        DB.session.add(user1)
        DB.session.commit()

@APP.cli.command()
def ResetDB():
    '''重置数据库'''
    DB.drop_all()


if __name__ == '__main__':
    APP.run(port=5000, debug=True)